// pages/collect/index.js
import { request } from '../../request/http.js';
import regeneratorRuntime from '../../lib/runtime/runtime.js';
Page({
  data: {
    // 收藏的商品
    collect: [],
    // 商品是否被收藏
    // isCollect: true,
    // 商品详情信息
    goodsInfo: {},
  },

  // 标题点击事件, 从子组件转递过来
  // handleTabsItemChange(e) {
  //   const { index } = e.detail;
  //   let { tabs } = this.data;
  //   tabs.forEach((v, i) => index == i ? v.isActive = true : v.isActive = false)
  //   this.setData({ tabs })
  // },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    let collect = wx.getStorageSync('collect');
    this.setData({ collect })
  },
//从collect缓存里删除
  deletecollect(e){
    let collect = wx.getStorageSync('collect') || [];
    // let { goods_id } = this.data.goodsInfo;
    // let index = collect.findIndex(v => v.goods_id == goods_id);
    console.log(e.currentTarget.dataset.index);
    let index = e.currentTarget.dataset.index;
    collect.splice(index, 1)
  
    wx.setStorageSync('collect', collect);
    this.setData({ collect })
    wx.showToast({ title: "从收藏夹里删除成功", icon: 'success', mask: true })

  },


  // // 获取商品详情
  // async getGoodsInfo(goodsId) {
  //   const result = await request({ name: 'goodsInfo', data: { goods_id: goodsId } });
  //   console.log(result.statusCode);

  //   // let collect = wx.getStorageSync('collect') || [];
 
  //   // let { goods_id } = result.data.message;
  //   // let isCollect = collect.some(v => v.goods_id == goods_id)
  //   console.log(result.data.message);
  //   this.setData({
  //     goodsInfo: result.data.message
  //   })
  // },

})